
define(["esri/toolbars/draw","widget/graphicUtils"],function(Draw,graphicUtils){
	var draw=null,drawHandle=null,map=null,graphic=null;
	return {
		getInstance:function(map){
			this.map= map;
			if(!map.draw){
				draw=new Draw(map);
				map.draw=draw;
			}
			return draw;
		},
		setActivate:function(type){
			draw.activate(Draw[type]);
		},
		deactivate:function(){
			if(draw){
			this.map.setMapCursor("default");
			draw.deactivate();
			}
		},
		setDrawEnd:function(drawEnd,callback){
			if(drawHandle){
				drawHandle.remove();
			}
			drawHandle=draw.on("draw-end",function(evt){
				if(drawEnd && typeof drawEnd=="function"){
					drawEnd(evt);
				}
				if(callback && typeof callback=="function"){
					callback();
				}
			});
		},
		remove:function(){
			//var graphic = graphicUtils.parseGraphic(geometry);
			this.map.graphics.remove(this.graphic);
		},
		addToMap:function(geometry){
			this.graphic = graphicUtils.parseGraphic(geometry);
			this.map.graphics.add(this.graphic);
			
		}
		
	}
});